<?php

class I18n
{
	/**
	 * @var string
	 */
	private static $_locale = null;

	/**
	 * @var string
	 */
	private static $_language = null;

	/**
	 * @var array
	 */
	private static $_messages = null;

	/**
	 * format date string
	 * @param int $value
	 * @return string
	 */
	static public function toDate($value)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}

		return date('Y-m-d', $value);
	}

	/**
	 * format date string
	 * @param int $value
	 * @return string
	 */
	static public function toDatetime($value)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}

		return date('Y-m-d H:i:s', $value);
	}

	/**
	 * @param int $value
	 * @return string
	 */
	static public function toTime($value)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}
		return date('H:i:s');
	}

	static public function toCurrency($value)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}
		return date('Y-m-d H:i:s');
	}

	/**
	 * format text message
	 */
	static public function __($message, $params = null)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}

		$lang = self::$_language;

		if (null == self::$_messages[$lang])
		{
			self::$_messages[$lang] = Agilet::loadConfig('language/' . $lang);
		}

		if (isset(self::$_messages[$lang][$message]))
		{
			$message = self::$_messages[$lang][$message];
		}

		return $message;
	}

	static public function setLocale($locale)
	{
		if (null == self::$_locale)
		{
			self::__init();
		}
		self::$_locale = $locale;
	}

	static public function setLanguage($language)
	{
		self::$_language = $language;
	}

	/**
	 * initialized locale value
	 * @param $locale
	 */
	static public function __init()
	{
		self::$_locale = 'vi_VN';
		self::$_language = 'vi';
	}

}

